/**
 * 数据字典工具类
 */
 import { useRepDictStoreWithOut } from '@/store/modules/repDict'
 import { ElementPlusInfoType } from '@/types/elementPlus'
 
 const dictStore = useRepDictStoreWithOut()
 
 /**
  * 获取 dictType 对应的数据字典数组
  *
  * @param dictType 数据类型
  * @returns {*|Array} 数据字典数组
  */
 export interface RepDictDataType {
   dictType: string
   label: string
   value: string | number | boolean
   colorType: ElementPlusInfoType | ''
   cssClass: string
 }
 
 export interface NumberDictDataType extends RepDictDataType {
   value: number
 }
 
 export interface StringDictDataType extends RepDictDataType {
   value: string
 }
 
 export const getRepDictOptions = (dictType: string) => {
   return dictStore.getDictByType(dictType) || []
 }
 
 export const getIntRepDictOptions = (dictType: string): NumberDictDataType[] => {
   // 获得通用的 DictDataType 列表
   const dictOptions: RepDictDataType[] = getRepDictOptions(dictType)
   // 转换成 number 类型的 NumberDictDataType 类型
   // why 需要特殊转换：避免 IDEA 在 v-for="dict in getIntDictOptions(...)" 时，el-option 的 key 会告警
   const dictOption: NumberDictDataType[] = []
   dictOptions.forEach((dict: RepDictDataType) => {
     dictOption.push({
       ...dict,
       value: parseInt(dict.value + '')
     })
   })
   return dictOption
 }
 
 export const getStrRepDictOptions = (dictType: string) => {
   // 获得通用的 DictDataType 列表
   const dictOptions: RepDictDataType[] = getRepDictOptions(dictType)
   // 转换成 string 类型的 StringDictDataType 类型
   // why 需要特殊转换：避免 IDEA 在 v-for="dict in getStrDictOptions(...)" 时，el-option 的 key 会告警
   const dictOption: StringDictDataType[] = []
   dictOptions.forEach((dict: RepDictDataType) => {
     dictOption.push({
       ...dict,
       value: dict.value + ''
     })
   })
   return dictOption
 }
 
 export const getBoolRepDictOptions = (dictType: string) => {
   const dictOption: RepDictDataType[] = []
   const dictOptions: RepDictDataType[] = getRepDictOptions(dictType)
   dictOptions.forEach((dict: RepDictDataType) => {
     dictOption.push({
       ...dict,
       value: dict.value + '' === 'true'
     })
   })
   return dictOption
 }
 
 /**
  * 获取指定字典类型的指定值对应的字典对象
  * @param dictType 字典类型
  * @param value 字典值
  * @return DictDataType 字典对象
  */
 export const getRepDictObj = (dictType: string, value: any): RepDictDataType | undefined => {
   const dictOptions: RepDictDataType[] = getRepDictOptions(dictType)
   for (const dict of dictOptions) {
     if (dict.value === value + '') {
       return dict
     }
   }
 }
 
 /**
  * 获得字典数据的文本展示
  *
  * @param dictType 字典类型
  * @param value 字典数据的值
  * @return 字典名称
  */
 export const getRepDictLabel = (dictType: string, value: any): string => {
   const dictOptions: RepDictDataType[] = getRepDictOptions(dictType)
   const dictLabel = ref('')
   dictOptions.forEach((dict: RepDictDataType) => {
     if (dict.value === value + '') {
       dictLabel.value = dict.label
     }
   })
   return dictLabel.value
 }
 
export enum REP_DICT_TYPE {
  PROJECT_ATTRIBUTE = "project_attribute",
  MANAGE_MODE = "manage_mode",
  PROJECT_STATUS = "project_status",
  BIDDING_METHOD = "bidding_method",
  BIDDING_LOCATION = "bidding_location",
  SUPPLY_SITUATION = "supply_situation",
  NOT_SUPPLY_REASON = "not_supply_reason",
  SUSTOMIZE_REPORT_TYPE = "customize_report_type",
  BASE_SOURCE = "base_source",
  MODE_PRODUCTION = "mode_production",
  CLUES_SOURCE = "clues_source",
  BELONGING_REGION = "belonging_region",
  DISPOSAL_RESULTS = "disposal_results",
  DISPOSAL_RESULTS1 = "disposal_results1",
  DISPOSAL_RESULTS2 = "disposal_results2",
  PROGRESS_STATUS = "progress_status",
  RISK_JUDGMENT = "risk_judgment",
  COLLECTION_WAY = "collection_way",
}
 